package com.eleadin.ruleengine.config;

import com.eleadin.ruleengine.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * @ClassName InterceptorConf
 * @Author zhaokang
 * @Description 要想是自定义拦截器生效需要实现此类
 * @Date 2021/1/21 15:13
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Autowired
    private LoginInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor);
    }

    /**
     * 解决swagger死循环问题
     * 下面这几个地址会一直轮询，改为重定向
     * /null/swagger-resources/configuration/ui
     * /null/swagger-resources/configuration/security
     * /null/swagger-resources
     */
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addRedirectViewController("/null/api-docs",
                "/api-docs").setKeepQueryParams(true);
        registry.addRedirectViewController("/null/swagger-resources/configuration/ui",
                "/swagger-resources/configuration/ui");
        registry.addRedirectViewController("/null/swagger-resources/configuration/security",
                "/swagger-resources/configuration/security");
        registry.addRedirectViewController("/null/swagger-resources", "/swagger-resources");
    }

}
